import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class Painel {

	private String usuario;
	
	public Painel( String usuario ) {
		
		this.usuario = usuario;
	}
	
	public static JPanel montaPainel() {
		
		JPanel painel = null;
		
	      ActionAdapter buttonListener = null;

	      // Create an options pane
	      JPanel optionsPane = new JPanel(new GridLayout(4, 1));

//	      // IP address input
//	      pane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
//	      pane.add(new JLabel("Host IP:"));
//	      ipField = new JTextField(10);
//	      ipField.setText(hostIP);
//	      ipField.setEnabled(false);
//	      ipField.addFocusListener(new FocusAdapter() {
//	            public void focusLost(FocusEvent e) {
//	               ipField.selectAll();
//	               // Should be editable only when disconnected
//	               if (connectionStatus != DISCONNECTED) {
//	                  changeStatusNTS(NULL, true);
//	               }
//	               else {
//	                  hostIP = ipField.getText();
//	               }
//	            }
//	         });
//	      pane.add(ipField);
//	      optionsPane.add(pane);

//	      // Port input
//	      pane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
//	      pane.add(new JLabel("Port:"));
//	      portField = new JTextField(10); portField.setEditable(true);
//	      portField.setText((new Integer(port)).toString());
//	      portField.addFocusListener(new FocusAdapter() {
//	            public void focusLost(FocusEvent e) {
//	               // should be editable only when disconnected
//	               if (connectionStatus != DISCONNECTED) {
//	                  changeStatusNTS(NULL, true);
//	               }
//	               else {
//	                  int temp;
//	                  try {
//	                     temp = Integer.parseInt(portField.getText());
//	                     port = temp;
//	                  }
//	                  catch (NumberFormatException nfe) {
//	                     portField.setText((new Integer(port)).toString());
//	                     mainFrame.repaint();
//	                  }
//	               }
//	            }
//	         });
//	      pane.add(portField);
//	      optionsPane.add(pane);

//	      // Host/guest option
//	      buttonListener = new ActionAdapter() {
//	            public void actionPerformed(ActionEvent e) {
//	               if (connectionStatus != DISCONNECTED) {
//	                  changeStatusNTS(NULL, true);
//	               }
//	               else {
//	                  isHost = e.getActionCommand().equals("host");
//
//	                  // Cannot supply host IP if host option is chosen
//	                  if (isHost) {
//	                     ipField.setEnabled(false);
//	                     ipField.setText("localhost");
//	                     hostIP = "localhost";
//	                  }
//	                  else {
//	                     ipField.setEnabled(true);
//	                  }
//	               }
//	            }
//	         };
//	      ButtonGroup bg = new ButtonGroup();
//	      hostOption = new JRadioButton("Host", true);
//	      hostOption.setMnemonic(KeyEvent.VK_H);
//	      hostOption.setActionCommand("host");
//	      hostOption.addActionListener(buttonListener);
//	      guestOption = new JRadioButton("Guest", false);
//	      guestOption.setMnemonic(KeyEvent.VK_G);
//	      guestOption.setActionCommand("guest");
//	      guestOption.addActionListener(buttonListener);
//	      bg.add(hostOption);
//	      bg.add(guestOption);
//	      pane = new JPanel(new GridLayout(1, 2));
//	      pane.add(hostOption);
//	      pane.add(guestOption);
//	      optionsPane.add(pane);

//	      // Connect/disconnect buttons
//	      JPanel buttonPane = new JPanel(new GridLayout(1, 2));
//	      buttonListener = new ActionAdapter() {
//	            public void actionPerformed(ActionEvent e) {
//	               // Request a connection initiation
//	               if (e.getActionCommand().equals("connect")) {
//	                  changeStatusNTS(BEGIN_CONNECT, true);
//	               }
//	               // Disconnect
//	               else {
//	                  changeStatusNTS(DISCONNECTING, true);
//	               }
//	            }
//	         };
//	      connectButton = new JButton("Connect");
//	      connectButton.setMnemonic(KeyEvent.VK_C);
//	      connectButton.setActionCommand("connect");
//	      connectButton.addActionListener(buttonListener);
//	      connectButton.setEnabled(true);
//	      disconnectButton = new JButton("Disconnect");
//	      disconnectButton.setMnemonic(KeyEvent.VK_D);
//	      disconnectButton.setActionCommand("disconnect");
//	      disconnectButton.addActionListener(buttonListener);
//	      disconnectButton.setEnabled(false);
//	      buttonPane.add(connectButton);
//	      buttonPane.add(disconnectButton);
//	      optionsPane.add(buttonPane);

	      //return optionsPane;
		
		return painel;
	}
	
	public JPanel painelChat(){
		
		JTextArea chatText = null;
		final JTextField chatLine = new JTextField();
		
		// Set up the chat pane
	      JPanel chatPane = new JPanel(new BorderLayout());
	      chatText = new JTextArea(10, 20);
	      chatText.setLineWrap(true);
	      chatText.setEditable(false);
	      chatText.setForeground(Color.blue);
	      JScrollPane chatTextPane = new JScrollPane(chatText,
	         JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
	         JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

	      chatLine.setEnabled( true );
	      
	      chatLine.addActionListener(new ActionAdapter() {
	    	  
	            public void actionPerformed(ActionEvent e) {
	               String s = chatLine.getText();
	               if (!s.equals("")) {
	                 // appendToChatBox("OUTGOING: " + s + "\n");
	                  chatLine.selectAll();
	                  
	                  // Send the string
	                 // sendString(s);
	               }
	            }
	         });
	      
	      chatPane.add(chatLine, BorderLayout.SOUTH);
	      chatPane.add(chatTextPane, BorderLayout.CENTER);
	      chatPane.setPreferredSize(new Dimension(200, 200));
	      
	      return chatPane;
	}
	
	public String getUsuario() {
		return usuario;
	}

	public void setUsuario(String usuario) {
		this.usuario = usuario;
	}

	class ActionAdapter implements ActionListener {
	   public void actionPerformed(ActionEvent e) {}
	}
	
}
